package cs3343.project.family;

import java.util.LinkedList;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;


/**
 * The Class Character.
 */
public class Character {
	
	/** The id. */
	private int id;
	
	/** The name. */
	private String name;
	
	/** The role. */
	private Role role;
	
	/** The map area id. */
	private int mapAreaId;
	
	/** The image. */
	private ImageIcon image;
	
	/** The gimage. */
	private ImageIcon gimage;
	
	/** The icon. */
	private ImageIcon icon;
	
	/** The esteem. */
	private int esteem;
	
	/** The died once. */
	private boolean diedOnce;
	
	/** The cards owned. */
	LinkedList<Card> cardsOwned = new LinkedList<Card>();

	/**
	 * Instantiates a new character.
	 *
	 * @param name the name
	 * @param image the image
	 * @param gimage the gimage
	 * @param icon the icon
	 */
	public Character(String name, ImageIcon image, ImageIcon gimage, ImageIcon icon) {
		this.name = name;
		this.mapAreaId = 0;
		this.image = image;
		this.gimage = gimage;
		this.icon = icon;
		this.esteem = 0;
		this.diedOnce = false;
		this.role = null;
	}
	
	/**
	 * Instantiates a new character.
	 *
	 * @param name the name
	 * @param esteem the esteem
	 */
	public Character(String name, int esteem) {
		this.name = name;
		this.esteem = esteem;
	}
	
	/**
	 * Gets the num of available card.
	 *
	 * @param cardType the card type
	 * @param cc the cc
	 * @return the num of available card
	 */
	public int getNumOfAvailableCard(String cardType, CardController cc) {
		int NumOfavailableCard = 0;
		
		for (int i = 0; i < cardsOwned.size(); i++) {
			if (cc.typeMatched(cardsOwned.get(i), cardType))
				NumOfavailableCard++;
		}
		
		return NumOfavailableCard;
	}
	
	/**
	 * Gets the available cards.
	 *
	 * @param cardType the card type
	 * @param cc the cc
	 * @return the available cards
	 */
	public String[] getAvailableCards(String cardType, CardController cc) {
		
		//get the combobox size
		int AvailableCardNum = getNumOfAvailableCard(cardType, cc);
		String[] option = new String[AvailableCardNum + 1];
		
		//add item to combobox
		if (AvailableCardNum == 0)
			option[0] = ConfigManager.getLangString("msgNoCardOption");
		else {
			option[0] = ConfigManager.getLangString("msgCardOption");
			
			for (int i = 0, j = 1; i < cardsOwned.size(); i++)
				if (cc.typeMatched(cardsOwned.get(i), cardType)) {
					option[j] = cardsOwned.get(i).getDescription();
					j++;
				}
		}		
		return option;
	} 

	/**
	 * Gets the name.
	 *
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name.
	 *
	 * @param name the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the id.
	 *
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * Sets the id.
	 *
	 * @param id the new id
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Gets the role.
	 *
	 * @return the role
	 */
	public Role getRole() {
		return role;
	}

	/**
	 * Sets the role.
	 *
	 * @param role the new role
	 */
	public void setRole(Role role) {
		this.role = role;
	}

	/**
	 * Gets the map area id.
	 *
	 * @return the map area id
	 */
	public int getMapAreaId() {
		return mapAreaId;
	}

	/**
	 * Sets the map area id.
	 *
	 * @param mapAreaId the new map area id
	 */
	public void setMapAreaId(int mapAreaId) {
		this.mapAreaId = mapAreaId;
	}

	/**
	 * Gets the image.
	 *
	 * @return the image
	 */
	public ImageIcon getImage() {
		return image;
	}

	/**
	 * Sets the image.
	 *
	 * @param image the new image
	 */
	public void setImage(ImageIcon image) {
		this.image = image;
	}
	
	/**
	 * Gets the g image.
	 *
	 * @return the g image
	 */
	public ImageIcon getGImage() {
		return gimage;
	}

	/**
	 * Sets the g image.
	 *
	 * @param image the new g image
	 */
	public void setGImage(ImageIcon image) {
		this.gimage = image;
	}

	/**
	 * Gets the icon.
	 *
	 * @return the icon
	 */
	public ImageIcon getIcon() {
		return icon;
	}

	/**
	 * Sets the icon.
	 *
	 * @param icon the new icon
	 */
	public void setIcon(ImageIcon icon) {
		this.icon = icon;
	}

	/**
	 * Gets the esteem.
	 *
	 * @return the esteem
	 */
	public int getEsteem() {
		return esteem;
	}

	/**
	 * Sets the esteem.
	 *
	 * @param esteem the new esteem
	 */
	public void setEsteem(int esteem) {
		this.esteem = esteem;
		
	}
	
	/**
	 * Adds the esteem.
	 *
	 * @param esteem the esteem
	 */
	public void addEsteem(int esteem) {
		this.esteem += esteem;
	}
	
	/**
	 * Minus esteem.
	 *
	 * @param esteem the esteem
	 */
	public void minusEsteem(int esteem) {
		this.esteem -= esteem;
	}
	
	/**
	 * Adds the card.
	 *
	 * @param card the card
	 */
	public void addCard(Card card) {
		if (cardsOwned.size() < 10)
			this.cardsOwned.add(card);
		else
			JOptionPane.showMessageDialog (null, ConfigManager.getLangString("msgTooManyCard"), ConfigManager.getLangString("infoTitle"), JOptionPane.INFORMATION_MESSAGE);
	}
	
	/**
	 * Removes the card.
	 *
	 * @param card the card
	 */
	public void removeCard(Card card) {
		this.cardsOwned.remove(card);
	}
	
	/**
	 * Gets the no of card owned.
	 *
	 * @return the no of card owned
	 */
	public int getNoOfCardOwned() {
		return this.cardsOwned.size();
	}
	
	/**
	 * Gets the cards owned.
	 *
	 * @return the cards owned
	 */
	public LinkedList<Card> getCardsOwned() {
		return this.cardsOwned;
	}

	/**
	 * Sets the cards owned.
	 *
	 * @param cardsOwned the new cards owned
	 */
	public void setCardsOwned(LinkedList<Card> cardsOwned) {
		this.cardsOwned = cardsOwned;
	}
	
	/**
	 * Sets the died once.
	 *
	 * @param b the new died once
	 */
	public void setDiedOnce(boolean b){
		this.diedOnce = b;
	}
	
	/**
	 * Gets the died once.
	 *
	 * @return the died once
	 */
	public boolean getDiedOnce(){
		return this.diedOnce;
	}
}
